package com.sm.healthy.model

import androidx.lifecycle.viewModelScope
import com.sm.healthy.base.App
import com.sm.healthy.data.bean.FetalEntity
import com.sm.healthy.ext.gson
import kotlinx.coroutines.launch
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.databind.BooleanObservableField
import me.hgj.jetpackmvvm.callback.databind.StringObservableField
import me.hgj.jetpackmvvm.util.LogUtils

class FetalHeartModel : BaseViewModel() {
    val fhrStr = StringObservableField("---")
    val fetalMovementStr = StringObservableField("---")
    var fetalMovementCount = 0
    val isStart = BooleanObservableField(false)

    val dao = App.database.fetalDao()

    fun insert(entity: FetalEntity) {
        LogUtils.debugInfo("csw", "data = ${gson.toJson(entity)}")
        viewModelScope.launch {
            dao.insert(entity)
        }
    }

    fun clear() {
        fetalMovementCount = 0
        fhrStr.set("---")
        fetalMovementStr.set("---")
    }
}